﻿@{
    ViewBag.Title = "类目管理";
    var collection = Request.QueryString;
}
@using MvcApplication.Entity
@model  PaginationResult<Category>

<div ms-controller="avalon">
    <div class="am-cf am-padding">
        <div class="am-fl am-cf">
            <strong class="am-text-primary am-text-lg">类目</strong> / 
        <small>Category</small>
        </div>
    </div>
    <div class="am-g" style="margin-bottom: 15px;">
        <form>
            <div class="am-u-sm-12 am-u-md-6">
                <div class="am-input-group am-input-group-sm">
                    <input type="text" class="am-form-field" name="name" value="@Request.QueryString["name"]">
                    <span class="am-input-group-btn">
                        <button class="am-btn am-btn-default" type="submit">搜索</button>
                    </span>
                </div>
            </div>
        </form>
    </div>
    <div class="am-g">
        <div class="am-u-sm-12 am-u-md-6">
            <div class="am-btn-toolbar">
                <div class="am-btn-group am-btn-group-xs">
                    <button type="button" class="am-btn am-btn-default" onclick="location.reload()">
                        <span class="am-icon-archive"></span>&nbsp;刷新
                    </button>
                    <button type="button" class="am-btn am-btn-default am-text-danger" onclick="beforeDelete()">
                        <span class="am-icon-trash-o am-text-danger"></span>&nbsp;删除
                    </button>
                </div>
            </div>
        </div>
    </div>

    <div class="am-g">
        <div class="am-u-sm-8">
            <form class="am-form" id="table-form">
                <table cellspacing="0" class="am-table am-table-striped am-table-hover table-main">
                    <thead>
                        <tr>
                            <th>
                                <input type="checkbox" onchange="totalCheck(this)" /></th>
                            <th>ID</th>
                            <th>类目</th>
                            <th>#操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var category in Model.Datas)
                        {
                            <tr>
                                <td>
                                    <input type="checkbox" name="categoryIDs" value="@category.ID"/>
                                </td>
                                <td>@category.ID</td>
                                <td style="width: 350px;">
                                    @category.Name
                                </td>
                                <td>
                                    <div class="am-btn-toolbar">
                                        <div class="am-btn-group am-btn-group-xs">
                                            <button type="button" 
                                                data-am-modal="{target: '#editCategoryModal', closeViaDimmer: 0, width: 400, height: 225}"
                                                class="am-btn am-btn-default am-text-success"
                                                ms-click="show_edit_modal(@category.ID)">
                                                <span class="am-icon-pencil-square-o am-text-success"></span>&nbsp;编辑
                                            </button>
                                            <button type="button" class="am-btn am-btn-default am-text-danger" onclick="beforeDelete(@category.ID)">
                                                <span class="am-icon-trash-o am-text-danger"></span>&nbsp;删除
                                            </button>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </form>
            <div>
                @{Html.RenderPartial("~/Views/Common/Pagination.cshtml", Model);}
            </div>
        </div>

        <div class="am-u-sm-4">
            <div class="am-panel am-panel-default">
                <div class="am-panel-hd am-cf" data-am-collapse="{target: '#collapse-panel-3'}">新建类目<span class="am-icon-chevron-down am-fr"></span></div>
                <div class="am-panel-bd am-collapse am-in" id="collapse-panel-3">
                    <form class="am-form" id="newCategory">
                        <div class="am-g am-margin-top-sm">
                            <div class="am-u-sm-12 am-u-md-12 am-u-end">
                                <input type="text" name="name" class="am-input-sm" placeholder="类目名">
                            </div>
                        </div>
                        <div class="am-g am-margin-top-sm">
                            <div class="am-u-sm-12 am-u-md-12 am-u-end">
                                <button class="am-btn am-btn-primary am-btn-xs"
                                    onclick="newCategory()"
                                    type="button">
                                    保存</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <!--编辑modal-->
    <div class="am-modal am-modal-no-btn" tabindex="-1" id="editCategoryModal">
        <div class="am-modal-dialog">
            <div class="am-modal-hd">
                编辑类目
      <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
            </div>
            <div class="am-modal-bd">
                <form class="am-form" id="edit_category">
                    <div class="am-g am-margin-top-sm">
                        <div class="am-u-sm-12 am-u-md-12 am-u-end">
                            <input type="hidden" name="ID" ms-duplex="categoryForEdit.ID"/>
                            <input type="text" name="name" class="am-input-sm" placeholder="类目名" ms-duplex="categoryForEdit.Name">
                        </div>
                    </div>
                    <div class="am-g am-margin-top-sm">
                        <div class="am-u-sm-12 am-u-md-12 am-u-end">
                            <button class="am-btn am-btn-primary am-btn-xs"
                                ms-click="save_category()"
                                type="button">
                                保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
@section scripts{
    <script src="~/Content/js/category/list.js"></script>
}